home *** CD-ROM | disk | FTP | other *** search
- /* -------------------------------------------- */
- /* Some functions to manipulate strings of char */
- /* By MaVaTi, for ClipWatch */
- /* -------------------------------------------- */
-
- /* Copy 2 strings with length specified */
- void strcpy_limited(char *StringDest,char *StringSrc,int Lgt)
- {
- int i;
- for(i=0;i<Lgt;i++)
- {
- StringDest[i]=StringSrc[i];
- }
- }
-
- /* Compare 2 strings with length specified */
- int strcmp_limited(char *String1,char *String2,int Lgt)
- {
- int i=0;
- int idem=TRUE;
- do
- {
- if(String1[i]!=String2[i])
- {
- idem=FALSE;
- }
- i++;
- }
- while((i<Lgt)&&(idem==TRUE));
- if (idem==TRUE)
- return 0;
- else
- return 1;
- }
-
- /* Copy 2 strings terminated with specials caracters (other than traditionnal '\0') */
- /* We can have 2 types of special caracters (ex:'\t' and '\n') */
- /* Put 0 if you have only 1 type of special caracter */
- /* End the new string with a '\0' caracter instead of the special caracter */
- void strcpy_termnotnull(char *StringDest,char *StringSrc,char SpecialTerm,char SpecialTerm2)
- {
- int i=0;
- char car;
- char end=FALSE;
- do
- {
- car=StringSrc[i];
- StringDest[i]=car;
- if ((car==SpecialTerm)||((SpecialTerm2!=0)&&(car==SpecialTerm2)))
- {
- StringDest[i]='\0';
- end=TRUE;
- }
- i++;
- }
- while(end!=TRUE);
- }
-
- /* Compare 2 strings terminated with specials caracters (other than traditionnal '\0') */
- /* We can have 2 types of special caracters (ex:'\t' and '\n') */
- /* Put 0 if you have only 1 type of special caracter */
- int strcmp_termnotnull(char *String1,char *String2,char SpecialTerm,char SpecialTerm2)
- {
- int i=0;
- char car;
- char end=FALSE;
- int idem=TRUE;
- do
- {
- car=String1[i];
- if ((car==SpecialTerm)||((SpecialTerm2!=0)&&(car==SpecialTerm2)))
- {
- end=TRUE;
- }
- if((car!=String2[i])&&(end==FALSE))
- {
- idem=FALSE;
- }
- i++;
- }
- while((end==FALSE)&&(idem==TRUE));
- if (idem==TRUE)
- return 0;
- else
- return 1;
- }
-
- /* Search a string into another one
- Back:pointer on the string found if found
- -----------------------------------------------------------
- String:pointer on the string to explore
- nbrcar:nbr of caracters of the string to explore
- StringKey:pointer on the string to found
- nbrcarkey:nbr of caracters of the string to found
- */
- char * str_pos(char *String,int nbrcar,char *StringKey,int nbrcarkey)
- {
- int i=0;
- int i_key;
- char *idem=NULL;
- char degage;
- do
- {
- /* Found same start... */
- if (String[i]==StringKey[0])
- {
- degage=FALSE;
- i_key=0;
- do
- {
- if (String[i+i_key]!=StringKey[i_key])
- {
- degage=TRUE;
- }
- i_key++;
- }
- while((i_key<nbrcarkey)&&(degage==FALSE));
- if (degage==FALSE)
- {
- idem=&String[i];
- }
- }
- i++;
- }
- while((i<nbrcar)&&(idem==NULL));
- return idem;
- }
-
- /* Extracting a string from a frame with many fields separated
- with a special caracter
- If found caracters ',' they're replaced with '.' ( for atof() )
- Back:give a pointer on the string searched
- -----------------------------------------------------------
- String:pointer on the string to explore
- nbrcar:nbr of caracters of the string to explore
- Champ:which field we're interested in
- Separateur:special caracter delimiting the differents fields
- */
- char * str_field(char *String,int nbrcar,int Champ,char Separateur)
- {
- int i=0;
- char car;
- int CptChamp=1;
- char *adrstart=NULL;
- /* Premier Champ sélectionné ? */
- if (Champ==1)
- {
- adrstart=String;
- }
- else
- {
- /* Recherche Séparateur de champ */
- do
- {
- car=String[i];
- if (car==Separateur)
- {
- CptChamp++;
- /*C'est le champ qui nous intéresse ?*/
- if (CptChamp==Champ)
- {
- adrstart=String+i+1;
- }
- }
- i++;
- }
- while((i<nbrcar)&&(CptChamp!=Champ));
- }
- /* Remplacement caractère ',' par le '.' (fonction atof!) */
- if (adrstart!=NULL)
- {
- do
- {
- car=String[i];
- if (car==',')
- {
- String[i]='.';
- }
- i++;
- }
- while(i<nbrcar);
- }
- return adrstart;
- }
-
- /* Generate a string from a number with a number of zeros in front required */
- void RealToStrWithZeros(char * strfmt,int nbrcar,unsigned long nbr)
- {
- int lackcar;
- int lgt;
- int i;
- sprintf(strfmt,"%d",nbr);
- lgt=strlen(strfmt);
- if (lgt<nbrcar)
- {
- lackcar=nbrcar-lgt;
- for(i=0;i<lackcar;i++)
- {
- strfmt[i]='0';
- }
- sprintf(strfmt+i,"%d",nbr);
- }
- }
-
-